package com.ld.poetry.aigc.codegeex.gclu.errorcorrection;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

class ExampleClass {
    private String privateField;

    public ExampleClass(String privateField) {
        this.privateField = privateField;
    }
    
    private void privateMethod() {
        System.out.println("Private method called");
    }
}

public class ReflectionChallenge {
    public static void main(String[] args) throws Exception {
        ExampleClass exampleObj = new ExampleClass("Reflection");

        Class<?> clazz = exampleObj.getClass();

        Field privateField = clazz.getDeclaredField("privateField");
        
        Method privateMethod = clazz.getDeclaredMethod("privateMethod");
        privateMethod.invoke(exampleObj);

        ExampleClass newInstance = (ExampleClass) clazz.getDeclaredConstructor(String.class).newInstance("NewInstance");
        System.out.println("Private field value of newInstance: " + privateField.get(newInstance));
    }
}
